package com.kclmedu.ribbon.service.impl;

import com.kclmedu.ribbon.service.IHelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/*************************
 *@ClassName HelloService
 *@Description 业务层
 *@Author yejf
 *@Date 2019-12-01 22:17
 *@Version 1.0
 */
@Service
public class HelloService implements IHelloService {

    @Autowired
    private RestTemplate template;

    @Override
    @HystrixCommand(fallbackMethod = "hiError")  //指定当目标服务不能提供服务时，断路后如何提示客户
    public String hiService(String name) {
        //通过 RestTemplate 来获取目标服务
        return template.getForObject("http://eureka-client-hi/hi?name="+name, String.class);
    }

    public String hiError(String name) {
        return "Hi, "+name+", Sorry, 本服务实例不能提供服务了";
    }
}
